﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.DependencyInjection;

namespace StyleMVVM.WCF.DependencyInjection
{
	public class WhenServiceIs : IExportCondition
	{
		private Type[] serviceTypes;

		public WhenServiceIs(params Type[] serviceTypes)
		{
			this.serviceTypes = serviceTypes;
		}

		public bool ConditionMeet(IDependencyInjectionContainer container,
		                          IInjectionContext injectionContext,
		                          IExportStrategy exportStrategy)
		{
			Type instanceOfServiceType = injectionContext.GetConditionValue("ServiceType") as Type;

			if (instanceOfServiceType != null)
			{
				foreach (Type serviceType in serviceTypes)
				{
					if (serviceType.IsAssignableFrom(instanceOfServiceType))
					{
						return true;
					}
				}
			}

			return false;
		}
	}
}